----------------------------------------------------------------------------
-- TABELA SYS_FUNCTIONALITY
----------------------------------------------------------------------------
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_FUNCTIONALITY_Delete')
	DROP PROC dbo.SP_SYS_FUNCTIONALITY_Delete
GO

----------------------------------------------------------------------------
-- Delete a single record from SYS_FUNCTIONALITY
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_FUNCTIONALITY_Delete
	@FNC_ID numeric(10, 0)
AS

DELETE	SYS_FUNCTIONALITY
WHERE 	FNC_ID = @FNC_ID

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_FUNCTIONALITY_Insert')
	DROP PROC dbo.SP_SYS_FUNCTIONALITY_Insert
GO

----------------------------------------------------------------------------
-- Insert a single record into SYS_FUNCTIONALITY
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_FUNCTIONALITY_Insert
	@FNC_DES nvarchar(100),
	@FNC_COD numeric(6,0),
	@FNC_ID_PAR numeric(10,0) = NULL
AS

INSERT SYS_FUNCTIONALITY(FNC_DES,FNC_COD,FNC_ID_PAR)
VALUES (@FNC_DES,@FNC_COD,@FNC_ID_PAR)

select @@IDENTITY;

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_FUNCTIONALITY_Update')
	DROP PROC dbo.SP_SYS_FUNCTIONALITY_Update
GO

----------------------------------------------------------------------------
-- Update a single record in SYS_FUNCTIONALITY
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_FUNCTIONALITY_Update
	@FNC_ID numeric(10,0),
	@FNC_DES nvarchar(100),
	@FNC_COD numeric(6,0),
	@FNC_ID_PAR numeric(10,0)
AS

UPDATE	SYS_FUNCTIONALITY
SET	FNC_DES = @FNC_DES,
	FNC_COD = @FNC_COD,
	FNC_ID_PAR = @FNC_ID_PAR
WHERE 	FNC_ID= @FNC_ID

GO

----------------------------------------------------------------------------
-- Select a single record from SYS_FUNCTIONALITY
----------------------------------------------------------------------------
CREATE VIEW dbo.VW_SYS_FUNCTIONALITY
AS

SELECT	FNC_ID,
	FNC_DES,
	FNC_COD,
	FNC_ID_PAR
FROM	SYS_FUNCTIONALITY

GO
----------------------------------------------------------------------------
-- TABELA SYS_FUNCTIONALITY_MENU
----------------------------------------------------------------------------
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_FUNCTIONALITY_MENU_Delete')
	DROP PROC dbo.SP_SYS_FUNCTIONALITY_MENU_Delete
GO

----------------------------------------------------------------------------
-- Delete a single record from SYS_FUNCTIONALITY_MENU
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_FUNCTIONALITY_MENU_Delete
	@FNC_MNU_ID numeric(10, 0)
AS

DELETE	SYS_FUNCTIONALITY_MENU
WHERE 	FNC_MNU_ID = @FNC_MNU_ID

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_FUNCTIONALITY_MENU_Insert')
	DROP PROC dbo.SP_SYS_FUNCTIONALITY_MENU_Insert
GO

----------------------------------------------------------------------------
-- Insert a single record into SYS_FUNCTIONALITY_MENU
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_FUNCTIONALITY_MENU_Insert
	@FNC_MNU_ID numeric(10,0),
	@FNC_MNU_DES nvarchar(100),
	@FNC_MNU_HNT nvarchar(400),
	@FNC_MNU_FLG_BAR nvarchar(2) = NULL
AS

INSERT SYS_FUNCTIONALITY_MENU(FNC_MNU_ID,FNC_MNU_DES,FNC_MNU_HNT,FNC_MNU_FLG_BAR)
VALUES (@FNC_MNU_ID,@FNC_MNU_DES,@FNC_MNU_HNT,COALESCE(@FNC_MNU_FLG_BAR,'N'))

select @@IDENTITY;

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_FUNCTIONALITY_MENU_Update')
	DROP PROC dbo.SP_SYS_FUNCTIONALITY_MENU_Update
GO

----------------------------------------------------------------------------
-- Update a single record in SYS_FUNCTIONALITY_MENU
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_FUNCTIONALITY_MENU_Update
	@FNC_MNU_ID numeric(10,0),
	@FNC_MNU_DES nvarchar(100),
	@FNC_MNU_HNT nvarchar(400),
	@FNC_MNU_FLG_BAR nvarchar(2)
AS

UPDATE	SYS_FUNCTIONALITY_MENU
SET	FNC_MNU_DES = @FNC_MNU_DES,
	FNC_MNU_HNT = @FNC_MNU_HNT,
	FNC_MNU_FLG_BAR = COALESCE(@FNC_MNU_FLG_BAR,'N')
WHERE 	FNC_MNU_ID= @FNC_MNU_ID

GO

IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.VW_SYS_FUNCTIONALITY_MENU')
	DROP VIEW dbo.VW_SYS_FUNCTIONALITY_MENU
GO

----------------------------------------------------------------------------
-- Select a single record from SYS_FUNCTIONALITY_MENU
----------------------------------------------------------------------------
CREATE VIEW dbo.VW_SYS_FUNCTIONALITY_MENU
AS

SELECT	FNC_MNU_ID,
	FNC_MNU_DES,
	FNC_MNU_HNT,
	FNC_MNU_FLG_BAR
FROM	SYS_FUNCTIONALITY_MENU

GO
----------------------------------------------------------------------------
-- TABELA SYS_LOG
----------------------------------------------------------------------------
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_LOG_Delete')
	DROP PROC dbo.SP_SYS_LOG_Delete
GO

----------------------------------------------------------------------------
-- Delete a single record from SYS_LOG
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_LOG_Delete
	@LOG_ID numeric(10, 0)
AS

DELETE	SYS_LOG
WHERE 	LOG_ID = @LOG_ID

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_LOG_Insert')
	DROP PROC dbo.SP_SYS_LOG_Insert
GO

----------------------------------------------------------------------------
-- Insert a single record into SYS_LOG
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_LOG_Insert
	@LOG_DTE datetime,
	@USR_ID numeric(10,0),
	@LOG_STS_ORI text = NULL,
	@LOG_STS_CUR text = NULL,
	@LOG_TAB_NAM nvarchar(100)
AS

INSERT SYS_LOG(LOG_DTE,USR_ID,LOG_STS_ORI,LOG_STS_CUR,LOG_TAB_NAM)
VALUES (@LOG_DTE,@USR_ID,@LOG_STS_ORI,@LOG_STS_CUR,@LOG_TAB_NAM)

select @@IDENTITY;

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_LOG_Update')
	DROP PROC dbo.SP_SYS_LOG_Update
GO

----------------------------------------------------------------------------
-- Update a single record in SYS_LOG
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_LOG_Update
	@LOG_ID numeric(10,0),
	@LOG_DTE datetime,
	@USR_ID numeric(10,0),
	@LOG_STS_ORI text,
	@LOG_STS_CUR text,
	@LOG_TAB_NAM nvarchar(100)
AS

UPDATE	SYS_LOG
SET	LOG_DTE = @LOG_DTE,
	USR_ID = @USR_ID,
	LOG_STS_ORI = @LOG_STS_ORI,
	LOG_STS_CUR = @LOG_STS_CUR,
	LOG_TAB_NAM = @LOG_TAB_NAM
WHERE 	LOG_ID= @LOG_ID

GO

IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.VW_SYS_LOG')
	DROP VIEW dbo.VW_SYS_LOG
GO

----------------------------------------------------------------------------
-- Select a single record from SYS_LOG
----------------------------------------------------------------------------
CREATE VIEW dbo.VW_SYS_LOG
AS

SELECT	LOG_ID,
	LOG_DTE,
	USR_ID,
	LOG_STS_ORI,
	LOG_STS_CUR,
	LOG_TAB_NAM
FROM	SYS_LOG

GO
----------------------------------------------------------------------------
-- TABELA SYS_PROFILE
----------------------------------------------------------------------------
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_PROFILE_Delete')
	DROP PROC dbo.SP_SYS_PROFILE_Delete
GO

----------------------------------------------------------------------------
-- Delete a single record from SYS_PROFILE
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_PROFILE_Delete
	@PFL_ID numeric(6, 0)
AS

DELETE	SYS_PROFILE
WHERE 	PFL_ID = @PFL_ID

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_PROFILE_Insert')
	DROP PROC dbo.SP_SYS_PROFILE_Insert
GO

----------------------------------------------------------------------------
-- Insert a single record into SYS_PROFILE
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_PROFILE_Insert
	@PFL_COD numeric(5,0),
	@PFL_DES nvarchar(200)
AS

INSERT SYS_PROFILE(PFL_COD,PFL_DES)
VALUES (@PFL_COD,@PFL_DES)

select @@IDENTITY;

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_PROFILE_Update')
	DROP PROC dbo.SP_SYS_PROFILE_Update
GO

----------------------------------------------------------------------------
-- Update a single record in SYS_PROFILE
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_PROFILE_Update
	@PFL_ID numeric(6,0),
	@PFL_COD numeric(5,0),
	@PFL_DES nvarchar(200)
AS

UPDATE	SYS_PROFILE
SET	PFL_COD = @PFL_COD,
	PFL_DES = @PFL_DES
WHERE 	PFL_ID= @PFL_ID

GO

IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.VW_SYS_PROFILE')
	DROP VIEW dbo.VW_SYS_PROFILE
GO

----------------------------------------------------------------------------
-- Select a single record from SYS_PROFILE
----------------------------------------------------------------------------
CREATE VIEW dbo.VW_SYS_PROFILE
AS

SELECT	PFL_ID,
	PFL_COD,
	PFL_DES
FROM	SYS_PROFILE

GO
----------------------------------------------------------------------------
-- TABELA SYS_PROFILE_FUNCTIONALITY
----------------------------------------------------------------------------
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_PROFILE_FUNCTIONALITY_Delete')
	DROP PROC dbo.SP_SYS_PROFILE_FUNCTIONALITY_Delete
GO

----------------------------------------------------------------------------
-- Delete a single record from SYS_PROFILE_FUNCTIONALITY
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_PROFILE_FUNCTIONALITY_Delete
	@PFL_ID numeric(10, 0)
AS

DELETE	SYS_PROFILE_FUNCTIONALITY
WHERE 	PFL_ID = @PFL_ID

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_PROFILE_FUNCTIONALITY_Insert')
	DROP PROC dbo.SP_SYS_PROFILE_FUNCTIONALITY_Insert
GO

----------------------------------------------------------------------------
-- Insert a single record into SYS_PROFILE_FUNCTIONALITY
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_PROFILE_FUNCTIONALITY_Insert
	@FNC_ID numeric(10,0),
	@PFL_ID numeric(6,0)
AS

INSERT SYS_PROFILE_FUNCTIONALITY(FNC_ID,PFL_ID)
VALUES (@FNC_ID,@PFL_ID)

GO
----------------------------------------------------------------------------
-- TABELA SYS_USER
----------------------------------------------------------------------------
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_USER_Delete')
	DROP PROC dbo.SP_SYS_USER_Delete
GO

----------------------------------------------------------------------------
-- Delete a single record from SYS_USER
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_USER_Delete
	@USR_ID numeric(10, 0)
AS

DELETE	SYS_USER
WHERE 	USR_ID = @USR_ID

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_USER_Insert')
	DROP PROC dbo.SP_SYS_USER_Insert
GO

----------------------------------------------------------------------------
-- Insert a single record into SYS_USER
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_USER_Insert
	@USR_LGN nvarchar(100),
	@USR_NAM nvarchar(200),
	@PFL_ID numeric(6,0)
AS

INSERT SYS_USER(USR_LGN,USR_NAM,PFL_ID)
VALUES (@USR_LGN,@USR_NAM,@PFL_ID)

select @@IDENTITY;

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_USER_Update')
	DROP PROC dbo.SP_SYS_USER_Update
GO

----------------------------------------------------------------------------
-- Update a single record in SYS_USER
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_USER_Update
	@USR_ID numeric(10,0),
	@USR_LGN nvarchar(100),
	@USR_NAM nvarchar(200),
	@PFL_ID numeric(6,0)
AS

UPDATE	SYS_USER
SET	USR_LGN = @USR_LGN,
	USR_NAM = @USR_NAM,
	PFL_ID = @PFL_ID
WHERE 	USR_ID= @USR_ID

GO

----------------------------------------------------------------------------
-- Select a single record from SYS_USER
----------------------------------------------------------------------------
CREATE VIEW dbo.VW_SYS_USER
AS

SELECT	USR_ID,
	USR_LGN,
	USR_NAM,
	PFL_ID
FROM	SYS_USER

GO
----------------------------------------------------------------------------
-- TABELA SYS_USER_PASSWORD
----------------------------------------------------------------------------
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_USER_PASSWORD_Delete')
	DROP PROC dbo.SP_SYS_USER_PASSWORD_Delete
GO

----------------------------------------------------------------------------
-- Delete a single record from SYS_USER_PASSWORD
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_USER_PASSWORD_Delete
	@USR_PWD_ID numeric(18, 0)
AS

DELETE	SYS_USER_PASSWORD
WHERE 	USR_PWD_ID = @USR_PWD_ID

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_USER_PASSWORD_Insert')
	DROP PROC dbo.SP_SYS_USER_PASSWORD_Insert
GO

----------------------------------------------------------------------------
-- Insert a single record into SYS_USER_PASSWORD
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_USER_PASSWORD_Insert
	@USR_PWD_ID numeric(18,0),
	@USR_ID numeric(10,0) = NULL,
	@USR_PWD_VAL nvarchar(64) = NULL,
	@USR_PWD_DTE_BGN datetime,
	@USR_PWD_DTE_END datetime
AS

INSERT SYS_USER_PASSWORD(USR_PWD_ID,USR_ID,USR_PWD_VAL,USR_PWD_DTE_BGN,USR_PWD_DTE_END)
VALUES (@USR_PWD_ID,@USR_ID,@USR_PWD_VAL,@USR_PWD_DTE_BGN,@USR_PWD_DTE_END)

select @@IDENTITY;

GO
IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.SP_SYS_USER_PASSWORD_Update')
	DROP PROC dbo.SP_SYS_USER_PASSWORD_Update
GO

----------------------------------------------------------------------------
-- Update a single record in SYS_USER_PASSWORD
----------------------------------------------------------------------------
CREATE PROC dbo.SP_SYS_USER_PASSWORD_Update
	@USR_PWD_ID numeric(18,0),
	@USR_ID numeric(10,0),
	@USR_PWD_VAL nvarchar(64),
	@USR_PWD_DTE_BGN datetime,
	@USR_PWD_DTE_END datetime
AS

UPDATE	SYS_USER_PASSWORD
SET	USR_ID = @USR_ID,
	USR_PWD_VAL = @USR_PWD_VAL,
	USR_PWD_DTE_BGN = @USR_PWD_DTE_BGN,
	USR_PWD_DTE_END = @USR_PWD_DTE_END
WHERE 	USR_PWD_ID= @USR_PWD_ID

GO

IF EXISTS(SELECT * FROM sysobjects WHERE name = 'dbo.VW_SYS_USER_PASSWORD')
	DROP VIEW dbo.VW_SYS_USER_PASSWORD
GO

----------------------------------------------------------------------------
-- Select a single record from SYS_USER_PASSWORD
----------------------------------------------------------------------------
CREATE VIEW dbo.VW_SYS_USER_PASSWORD
AS

SELECT	USR_PWD_ID,
	USR_ID,
	USR_PWD_VAL,
	USR_PWD_DTE_BGN,
	USR_PWD_DTE_END
FROM	SYS_USER_PASSWORD

GO
